package com.ship.contract.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ship.common.security.utils.SecurityUtils;
import com.ship.contract.bean.ConOperate;
import com.ship.contract.mapper.ConOperateMapper;
import com.ship.contract.service.ConOperateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @author tangshixuan
 * @date 2023-9-1
 */
@Service
public class ConOperateServiceImpl extends ServiceImpl<ConOperateMapper, ConOperate> implements ConOperateService {

    @Autowired
    private ConOperateMapper conOperateMapper;

    @Override
    public List<ConOperate> listByConId(Long id) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("con_id",id);
        queryWrapper.orderByDesc("opt_time");
        return super.list(queryWrapper);
    }

    @Override
    public void saveByCon(String optType,Long conId) {
        ConOperate conOperate = new ConOperate();
        conOperate.setOptType(optType);
        conOperate.setConId(conId);
        conOperate.setOptTime(new Date());
        conOperate.setOptPersonnel(SecurityUtils.getUsername());
        super.save(conOperate);
    }
}
